package com.hongminzheng.openapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongminzheng.openapi.mapper.RechargeMapper;
import com.hongminzheng.openapi.pojo.Recharge;
import com.hongminzheng.openapi.service.RechargeService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author hmz
 * @version v1.0
 * @data 2020/09/29
 **/

@Service
@Transactional(rollbackFor = Exception.class)
@Log4j
public class RechargeServiceImpl implements RechargeService {

    @Autowired
    private RechargeMapper rechargeMapper;

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return rechargeMapper.deleteByPrimaryKey(id);
    }

    /**
     * 增加
     * @param recharge
     * @return
     */
    @Override
    public int insert(Recharge recharge) {
        recharge.setCreateTime(new Date());
        recharge.setUpdateTime(new Date());
        return rechargeMapper.insert(recharge);
    }

    @Override
    public int insertSelective(Recharge recharge) {
        return rechargeMapper.insertSelective(recharge);
    }

    @Override
    public Recharge selectByPrimaryKey(Integer id) {
        return rechargeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Recharge recharge) {
        recharge.setUpdateTime(new Date());
        return rechargeMapper.updateByPrimaryKeySelective(recharge);
    }

    /**
     * 更新
     * @param recharge
     * @return
     */
    @Override
    public int updateByPrimaryKey(Recharge recharge) {
        recharge.setUpdateTime(new Date());
        return rechargeMapper.updateByPrimaryKey(recharge);
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Recharge> findAllRecharge() {
        return rechargeMapper.findAllRecharge();
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<Recharge> findPage(Integer pageNum, Integer pageSize) throws Exception {
        PageHelper.startPage(pageNum, pageSize);
        List<Recharge> recharges = rechargeMapper.findAllRecharge();
        PageInfo<Recharge> pageInfo = new PageInfo<>(recharges);
        return pageInfo;
    }



}
